﻿using Soft.Xml;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace Soft.Service
{

    /// <summary>
    /// 获取DllConfig节点
    /// </summary>
    public sealed class DllConfig : BaseSubElement, IEnumerable<ClassConfig>, IEnumerable
    {

        public DllConfig(XmlElement current) : base(current)
        {
        }


        /// <summary>
        ///获取配置文件的路径
        /// </summary>
        public string File
        {
            get
            {
                return base.CurrentElement.GetAttribute("File");
            }
            set
            {
                base.CurrentElement.SetAttribute("File", value);
            }
        }


        /// <summary>
        /// ClassCofig的数量
        /// </summary>
        public int ClassCount
        {
            get
            {
                return base.CurrentElement.SelectNodes(typeof(ClassConfig).Name).Count;
            }
        }

     
        public ClassConfig this[int index]
        {
            get
            {
                return new ClassConfig((XmlElement)base.CurrentElement.SelectNodes(typeof(ClassConfig).Name)[index]);
            }
        }


        public ClassConfig CreateClassConfig()
        {
            XmlElement xmlElement = base.CurrentElement.OwnerDocument.CreateElement(typeof(ClassConfig).Name);
            base.CurrentElement.AppendChild(xmlElement);
            return new ClassConfig(xmlElement);
        }

  
        public void Clear()
        {
            base.CurrentElement.InnerXml = "";
        }


        public void Remove(ClassConfig item)
        {
            base.CurrentElement.RemoveChild(item.CurrentElement);
        }


        public IEnumerator<ClassConfig> GetEnumerator()
        {
            foreach (object obj in base.CurrentElement.SelectNodes(typeof(ClassConfig).Name))
            {
                XmlNode xmlNode = (XmlNode)obj;
                yield return new ClassConfig((XmlElement)xmlNode);
            }
        }


        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }


    }
}
